package com.itheima.jdbctemplate;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 * @author wz
 * @description:
 * @date 2021-10-31
 */
public class JdbcTemplateDemo {

    /**
     * 实现增删改查
     *
     * @param args
     */
    public static void main(String[] args) {
        // 构建数据源 连接池对象
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("1234");
        dataSource.setUrl("jdbc:mysql:///heima01");
        // 构建jdbc 模板对象
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        // 调用模板对象api完后操作
        String insert = "insert into account values(null,?,?)";
        String update = "update account set name=? where id=?";
        String delete = "delete from account where id=?";

        int count = jdbcTemplate.update(delete, 4);
        System.out.println(count);
    }

}
